package com.moduleSys.resources;

import com.moduleSys.resources.xss.XssFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

import javax.servlet.DispatcherType;

/**
 * Created by czw on 2017/7/13 0013.
 */
@Configuration
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {

        registry.addResourceHandler("/resources/**","/**")
                .addResourceLocations("/WEB-INF/resources/","/WEB-INF/views/");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
       // registry.addInterceptor(new MyInterceptor()).addPathPatterns("/**");
        super.addInterceptors(registry);
    }

 /*   @Bean
    public UrlBasedViewResolver viewResolver() {
        UrlBasedViewResolver viewResolver = new UrlBasedViewResolver();
        viewResolver.setViewClass(JstlView.class);
        viewResolver.setPrefix("/WEB-INF/views/");
        viewResolver.setSuffix(".jsp");
        return viewResolver;
    }*/
 @Bean
 public FilterRegistrationBean xssFilterRegistration() {
     FilterRegistrationBean registration = new FilterRegistrationBean();
     registration.setDispatcherTypes(DispatcherType.REQUEST);
     registration.setFilter(new XssFilter());
     registration.addUrlPatterns("/*");
     registration.setName("xssFilter");
     registration.setOrder(Integer.MAX_VALUE);
     return registration;
 }
}
